// VBConversions Note: VB project level imports
using System.Data;
using DevExpress.XtraEditors.Controls;
using System.Diagnostics;
using System.Xml.Linq;
using DevExpress.XtraEditors.Repository;
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.VisualBasic;
using System.Configuration;
using System.Collections;
using DevExpress.XtraEditors;
using System.Data.Sql;
using Microsoft.SqlServer;
using System.Windows.Forms;
using System;
using DevExpress.XtraReports;
using Microsoft.SqlServer.Management.Smo;
using DevExpress;
using System.Linq;
using System.IO;
// End of VB project level imports


/// <summary>
/// CRUD by default is Disable except when de ControlCD is not define. CRUD is enable
/// </summary>
/// <remarks>Make sure to configure your metacontrol Property</remarks>
namespace SCIEF.SysBFW.CommonExt
{
	public class MetaQueryAccess
	{
		private bool _AllowCreate = false;
		public bool AllowCreate
		{
			get
			{
				return _AllowCreate;
			}
			set
			{
				_AllowCreate = value;
			}
		}
		private short _AllowRead = 0;
		public short AllowRead
		{
			get
			{
				return _AllowRead;
			}
			set
			{
				_AllowRead = value;
			}
		}
		private bool _AllowUpdate = false;
		public bool AllowUpdate
		{
			get
			{
				return _AllowUpdate;
			}
			set
			{
				_AllowUpdate = value;
			}
		}
		private bool _AllowDelete = false;
		public bool AllowDelete
		{
			get
			{
				return _AllowDelete;
			}
			set
			{
				_AllowDelete = value;
			}
		}
		public string ControlCd {get; set;}
		
		public MetaQueryAccess()
		{
		}
		
		public MetaQueryAccess(string controlCd)
		{
			AssignSecurity(controlCd);
		}
		
		public void AssignSecurity(string controlCd)
		{
			DataRow drow = default(DataRow);
			
			using (DataView dataView = Base.AppManager.GetControlSecurity(controlCd, "METAQ"))
			{
				if (dataView != null && dataView.Count > 0)
				{
					this.ControlCd = controlCd;
					
					for (int i = 0; i <= dataView.Count - 1; i++)
					{
						drow = dataView[i].Row;
						switch (drow["Property"].ToString())
						{
							case "AllowCreate":
								AllowCreate = System.Convert.ToBoolean(drow["Value"]);
								break;
							case "AllowRead":
								AllowRead = System.Convert.ToInt16(drow["Value"]);
								break;
							case "AllowUpdate":
								AllowUpdate = System.Convert.ToBoolean(drow["Value"]);
								break;
							case "AllowDelete":
								AllowDelete = System.Convert.ToBoolean(drow["Value"]);
								break;
							default:
								break;
						}
					}
				}
				else
				{
					AllowRead = System.Convert.ToInt16(true);
					AllowCreate = true;
					AllowUpdate = true;
					AllowDelete = true;
				}
				
			}
			
		}
	}
	
	
}
